<?php
/*************************************************************************************
 *
 *	FileName: header_php.php
 *	Desc    : search the product or shop for the user's list
 *	Author  : Seal
 *	Date    : 2010-1-30
 *
 *************************************************************************************/

	require_once ( LIB_DIR.'classes/Pager.php' );
	
	if( isset($_GET['search_cate']) && $_GET['search_cate'] == "product" )
	{
		require_once ( LIB_DIR.'search/productsearch.php' );
		
		$keyword = $_GET['q'];

		//not required field
		$category = '';
		$sortby = '';
		$location = '';
		$plat_id = '';
		$payment = '';
		$feature = '';
		$pricestart = '';
		$priceend = '';
		$page = 1;
		
	    if( isset( $_GET['p'] ) ){
	        $page = intval( $_GET['p'] );
		}
	
		$productSearch = new ProductSearch();
		$searchType = NORMAL_QUERY;
	
		//clean keyword
		$keyword = $productSearch->CleanKeyword( $keyword );
		
		// move page var keyword forward
		$pageVars['keyword'] = $keyword;
	
		//determine the search type
		$filterArray = array();
		$additionalKeyword = array();
		
		
		$isDesc = false;
	
		//assemble keyword
		foreach( $additionalKeyword as $key=>$value ) {
			$keyword .= " $key $value";
		}
	
		$result = array();
	
		
		$result = $productSearch->Query( '@product_name ' . $keyword, $page );
		
		
		$pageVars['result'] = $result;
		
		
		if( $result['total'] > 0 && !empty($result['matchIds']) ) 
		{
			$productDAO = GetProductDAO();
			$search_result = $productDAO->GetProductSimpleInfo( $result['matchIds'] );
		}
	
				
		$pageObj = new Pager(edp_href_link("ajax_search_in_list/?tiny=1&search_cate=product&q=".urlencode($keyword)),
				$pageVars['result']['total'], SHOP_INFO_PER_PAGE, $page, UP_RESULT_PAGE );
				
			
	}
	else if( isset($_GET['search_cate']) && ( $_GET['search_cate'] == "shop" || $_GET['search_cate'] == 'mall') )
	{
		$keyword = $_GET['q'];
		$page = 1;
		
		if( isset( $_GET['p'] ) ) 
			$page = intval( $_GET['p'] );
		
		$shopDao = GetShopDAO();
		$isMall = $_GET['search_cate'] == 'shop' ? false : true;
		list( $resultCount , $search_result ) = $shopDao->GetShopByKeyword( '@(shop_name,nick) ' . $keyword,  $isMall, $page, SHOP_INFO_PER_PAGE);
		$pageObj = new Pager( edp_href_link("ajax_search_in_list","tiny=1&search_cate=shop&q=".urlencode($keyword)), $resultCount, SHOP_INFO_PER_PAGE, $page, UP_RESULT_PAGE );
		$pageVars['pagebar'] = $pageObj->getBar();
	}
	else
	{
		echo "错误，请稍后再试!";
		edp_exit();
	}
		
	
?>